/*
	compile:
	alc-on; g++ wrap.cpp -L../lib -lBox2D -I.. -O3 -Wextra -fpack-struct -swc -o Box2DWrap.swc; alc-off
*/
#include <stdlib.h>
#include <stdio.h>
#include "AS3.h"
#include "Box2D/Box2D.h";

AS3_Val as3_ts;
#define TS(string) as3_ts = AS3_String(string); AS3_Trace(as3_ts); AS3_Release(as3_ts);
#define T(s); TS(#s);

AS3_Val as3_ptr;
#define return_as3_ptr(ptr) AS3_Release(as3_ptr); as3_ptr = AS3_Ptr(ptr); return as3_ptr;
#define return_null return AS3_Null();
#define return_bool(b) return b?AS3_True():AS3_False();

#define return_as3_object(wrap) AS3_Acquire(wrap);return wrap;

#define as3_new(type) AS3_Val type##_new(void* data, AS3_Val args) { return_as3_ptr(new type()); };

extern int32 b2_gjkCalls, b2_gjkIters, b2_gjkMaxIters;
extern int32 b2_toiCalls, b2_toiIters, b2_toiMaxIters;
extern int32 b2_toiRootIters, b2_toiMaxRootIters;


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Wrapper
class b2Wrap
{
public:
	b2Wrap(AS3_Val wrap)
	{
		this->wrap = wrap;
	}
	AS3_Val wrap;
};

class b2WorldWrap:public b2World,public b2Wrap{
public:
	b2WorldWrap(AS3_Val wrap,const b2Vec2 & gravity,bool doSleep):
	  b2Wrap(wrap)
		  ,b2World(gravity,doSleep)
	  {

	  }
};

class b2DrawWrap:public b2Draw,public b2Wrap
{
public:
	b2DrawWrap(AS3_Val wrap):
		b2Wrap(wrap)
	{

	}
public:
	void DrawPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color){
		AS3_CallTS("cDrawPolygon",wrap,"PtrType,IntType,PtrType",vertices,vertexCount,&color);
	}
	void DrawSolidPolygon (const b2Vec2 *vertices, int32 vertexCount, const b2Color &color)
	{
		AS3_CallTS("cDrawSolidPolygon",wrap,"PtrType,IntType,PtrType",vertices,vertexCount,&color);
	}
	void DrawCircle (const b2Vec2 &center, float32 radius, const b2Color &color)
	{
		AS3_CallTS("cDrawCircle",wrap,"PtrType,DoubleType,PtrType",&center,radius,&color);
	}
	void DrawSolidCircle (const b2Vec2 &center, float32 radius, const b2Vec2 &axis, const b2Color &color)
	{
		AS3_CallTS("cDrawSolidCircle",wrap,"PtrType,DoubleType,PtrType,PtrType",&center,radius,&axis,&color);
	}
	void DrawSegment (const b2Vec2 &p1, const b2Vec2 &p2, const b2Color &color)
	{
		AS3_CallTS("cDrawSegment",wrap,"PtrType,PtrType,PtrType",&p1,&p2,&color);
	}
	void DrawTransform (const b2Transform &xf)
	{
		AS3_CallTS("cDrawTransform",wrap,"PtrType",&xf);
	}
};
class b2DestructionListenerWrap:public b2DestructionListener,public b2Wrap
{
public:
	b2DestructionListenerWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	  {
	  }
public:
	void SayGoodbye(b2Fixture* fixture)
	{
		AS3_Val asFixture = AS3_Val(fixture->GetUserData());
		AS3_CallTS("SayGoodbyeFixture",wrap,"AS3ValType",asFixture);
	}
	void SayGoodbye(b2Joint* joint)
	{
		AS3_Val asJoint = AS3_Val(joint->GetUserData());
		AS3_CallTS("SayGoodbyeJoint",wrap,"AS3ValType",asJoint);
	}
};
class b2ContactListenerWrap:public b2ContactListener,public b2Wrap
{
public:
	b2ContactListenerWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	  {

	  }
public:
	void BeginContact (b2Contact *contact)
	{
		AS3_CallTS("cBeginContact",wrap,"PtrType",contact);
	}
	void EndContact (b2Contact *contact)
	{
		AS3_CallTS("cEndContact",wrap,"PtrType",contact);
	}
	void PreSolve (b2Contact *contact, const b2Manifold *oldManifold)
	{
		AS3_CallTS("cPreSolve",wrap,"PtrType,PtrType",contact,oldManifold);
	}
	void PostSolve (b2Contact *contact, const b2ContactImpulse *impulse)
	{
		AS3_CallTS("cPostSolve",wrap,"PtrType,PtrType",contact,impulse);
	}
};
class b2ContactFilterWrap:public b2ContactFilter,public b2Wrap
{
public:
	b2ContactFilterWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	  {

	  }
public:
	virtual bool ShouldCollide (b2Fixture *fixtureA, b2Fixture *fixtureB)
	{
		AS3_Val asFixtureA = AS3_Val(fixtureA->GetUserData());
		AS3_Val asFixtureB = AS3_Val(fixtureB->GetUserData());
		int result = AS3_IntValue(AS3_CallTS("ShouldCollide",wrap,"AS3ValType,AS3ValType",asFixtureA,asFixtureB));
		return 1==result;
	}
	bool CallSuperShouldCollide (b2Fixture *fixtureA, b2Fixture *fixtureB)
	{
		return b2ContactFilter::ShouldCollide(fixtureA,fixtureB);		
	}
};
class b2DynamicTreeWrap:public b2DynamicTree,public b2Wrap
{
public:
	b2DynamicTreeWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	{

	}
public:	
	bool QueryCallback(int32 proxyId)
	{
		int result = AS3_IntValue(AS3_CallTS("QueryCallback",wrap,"IntType",proxyId));
		return 1==result;
	}
	float32 RayCastCallback(const b2RayCastInput& input, int32 proxyId)
	{
		return AS3_NumberValue(AS3_CallTS("cRayCastCallback",wrap,"PtrType,IntType",&input,proxyId));
	}
};
class b2QueryCallbackWrap:public b2QueryCallback,public b2Wrap
{
public:
	b2QueryCallbackWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	  {

	  }
public:
	bool ReportFixture(b2Fixture* fixture)
	{
		int result =AS3_IntValue(AS3_CallTS("ReportFixture",wrap,"AS3ValType",AS3_Val(fixture->GetUserData())));
		return 1==result;
	}
};
class b2RayCastCallbackWrap:public b2RayCastCallback,public b2Wrap
{
public:
	b2RayCastCallbackWrap(AS3_Val wrap):
	  b2Wrap(wrap)
	  {

	  }
public:
	float32 ReportFixture(	b2Fixture* fixture, const b2Vec2& point,
		const b2Vec2& normal, float32 fraction)
	{
		return AS3_NumberValue(AS3_CallTS("cReportFixture",wrap,"AS3ValType,PtrType,PtrType,DoubleType",AS3_Val(fixture->GetUserData()),&point,&normal,fraction));
	}
};

#define e_customController 6
class b2CustomControllerDef;
class b2CustomController:public b2Controller
{
private:
	AS3_Val _defWrap;
protected:
	void Destroy(b2BlockAllocator* allocator)
	{
		allocator->Free(this, sizeof(b2CustomController));
	}
private:
	friend class b2CustomControllerDef;
	b2CustomController(const b2CustomControllerDef* def);
public:
	void Step(const b2TimeStep& step)
	{
		AS3_CallTS("cStep",AS3_Val(m_userData),"PtrType",&step);
	}
	void AddBody(b2Body* body)
	{
		AS3_CallTS("onAddBody",AS3_Val(m_userData),"AS3ValType",AS3_Val(body->GetUserData()));
		b2Controller::AddBody(body);
	}
	void RemoveBody(b2Body* body)
	{
		AS3_CallTS("onRemoveBody",AS3_Val(m_userData),"AS3ValType",AS3_Val(body->GetUserData()));
		b2Controller::RemoveBody(body);
	}
public:
	AS3_Val getDefWrap();
};
class b2CustomControllerDef:public b2ControllerDef,public b2Wrap
{
public:
	b2CustomControllerDef(AS3_Val wrap):
	  b2Wrap(wrap)
	  {

	  }
private:
	b2CustomController* Create(b2BlockAllocator* allocator)
	{
		void* mem = allocator->Allocate(sizeof(b2CustomController));
		return new (mem) b2CustomController(this);
	}
};

inline b2CustomController::b2CustomController(const b2CustomControllerDef* def):b2Controller(def)
{
	m_type = (b2ControllerType)e_customController;
	_defWrap = def->wrap;
}
inline AS3_Val b2CustomController::getDefWrap(){return _defWrap;}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2AABB
as3_new(b2AABB);
static AS3_Val b2AABB_Copy(void* data, AS3_Val args)
{
	b2AABB* ptr;
	b2AABB* source;
	AS3_ArrayValue(args, "PtrType,PtrType",&ptr,&source);
	*ptr = *source;
	return_null;
}
static AS3_Val b2AABB_GetCenter(void* data, AS3_Val args)
{
	b2AABB* ptr;
	AS3_ArrayValue(args, "PtrType",&ptr);
	return_as3_ptr(new b2Vec2(ptr->GetCenter()));
}
static AS3_Val b2AABB_GetExtents(void* data, AS3_Val args)
{
	b2AABB* ptr;
	AS3_ArrayValue(args, "PtrType",&ptr);
	return_as3_ptr(new b2Vec2(ptr->GetExtents()));
}
static AS3_Val b2AABB_Combine(void* data, AS3_Val args)
{
	b2AABB* ptr;
	b2AABB* aabb1;
	b2AABB* aabb2;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType",&ptr,&aabb1,&aabb2);
	ptr->Combine(*aabb1,*aabb2);
	return_null;
}
static AS3_Val b2AABB_Contains(void* data, AS3_Val args)
{
	b2AABB* ptr;
	b2AABB* aabb;
	AS3_ArrayValue(args, "PtrType,PtrType",&ptr,&aabb);
	return_bool(ptr->Contains(*aabb));
}
static AS3_Val b2AABB_RayCast(void* data, AS3_Val args)
{
	b2AABB* ptr;
	b2RayCastOutput * output;
	b2RayCastInput * input;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType",&ptr,&output,&input);
	return_bool(ptr->RayCast(output,*input));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Color
as3_new(b2Color);
static AS3_Val b2Color_Set(void* data, AS3_Val args)
{
	b2Color* ptr;
	double r;
	double g;
	double b;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType,DoubleType",&ptr,&r,&g,&b);
	ptr->Set(r,g,b);
	return_null;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Vec2
static AS3_Val b2Vec2_new(void* data, AS3_Val args)
{
	double x;
	double y;
	AS3_ArrayValue(args, "DoubleType,DoubleType", &x,&y);
	return_as3_ptr(new b2Vec2(x,y));
}
static AS3_Val b2Vec2_Array_new(void* data, AS3_Val args)
{
	int count;
	AS3_ArrayValue(args, "IntType", &count);
	b2Vec2 * ar = new b2Vec2[count];
	return_as3_ptr(ar);
}
static AS3_Val b2Vec2_SetZero(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->SetZero();
	return_null;
}
static AS3_Val b2Vec2_Set(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	double x;
	double y;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType", &ptr,&x,&y);
	ptr->Set(x,y);
	return_null;
}
static AS3_Val b2Vec2_Length(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->Length());
}
static AS3_Val b2Vec2_LengthSquared(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->LengthSquared());
}
static AS3_Val b2Vec2_Normalize(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->Normalize());
}
static AS3_Val b2Vec2_IsValid(void* data, AS3_Val args)
{
	b2Vec2 * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsValid()?AS3_True():AS3_False();
}
as3_new(b2Vec3);

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2World
static AS3_Val b2World_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	b2Vec2* gravity;
	int doSleep;
	AS3_ArrayValue(args, "AS3ValType,PtrType,IntType", &wrap,&gravity,&doSleep);
	return_as3_ptr(new b2WorldWrap(wrap,*gravity,doSleep==1));
}
static AS3_Val b2World_delete(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	delete ptr;
	return_null;
}
static AS3_Val b2World_SetDestructionListener(void* data, AS3_Val args)
{
	b2World* ptr;
	b2DestructionListener* listener;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&listener);
	ptr->SetDestructionListener(listener);
	return_null;
}

static AS3_Val b2World_SetContactFilter(void* data, AS3_Val args)
{
	b2World* ptr;
	b2ContactFilter * filter;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&filter);
	ptr->SetContactFilter(filter);
	return_null;
}
static AS3_Val b2World_GetContactFilter(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	b2ContactFilterWrap * filter = (b2ContactFilterWrap*)ptr->GetContactManager().m_contactFilter;
	return_as3_object(filter->wrap);
}

static AS3_Val b2World_SetContactListener(void* data, AS3_Val args)
{
	b2World* ptr;
	b2ContactListener * listener;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&listener);
	ptr->SetContactListener(listener);
	return_null;
}
static AS3_Val b2World_SetDebugDraw(void* data, AS3_Val args)
{
	b2World* ptr;
	b2Draw * draw;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&draw);
	ptr->SetDebugDraw(draw);
	return_null;
}

static AS3_Val b2World_CreateBody(void* data, AS3_Val args)
{
	b2World* ptr;
	b2BodyDef* def;
	AS3_Val wrap;
	AS3_ArrayValue(args, "PtrType,PtrType,AS3ValType", &ptr,&def,&wrap);
	b2Body* body = ptr->CreateBody(def);
	body->SetUserData(wrap);
	return_as3_ptr(body);
}
static AS3_Val b2World_DestroyBody(void* data, AS3_Val args)
{
	b2World* ptr;
	b2Body* body;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&body);
	ptr->DestroyBody(body);
	return_null;
}
static AS3_Val b2World_CreateJoint(void* data, AS3_Val args)
{
	b2World* ptr;
	b2JointDef* def;
	AS3_Val wrap;
	AS3_ArrayValue(args, "PtrType,PtrType,AS3ValType", &ptr,&def,&wrap);
	b2Joint* joint = ptr->CreateJoint(def);
	joint->SetUserData(wrap);
	return_as3_ptr(joint);
}
static AS3_Val b2World_DestroyJoint(void* data, AS3_Val args)
{
	b2World* ptr;
	b2Joint* joint;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&joint);
	ptr->DestroyJoint(joint);
	return_null;
}

static AS3_Val b2World_CreateController(void* data, AS3_Val args)
{
	b2World* ptr;
	b2ControllerDef* def;
	AS3_Val wrap;
	AS3_ArrayValue(args, "PtrType,PtrType,AS3ValType", &ptr,&def,&wrap);
	b2Controller* controller = ptr->CreateController(def);
	controller->SetUserData(wrap);
	return_as3_ptr(controller);
}
static AS3_Val b2World_DestroyController(void* data, AS3_Val args)
{
	b2World* ptr;
	b2Controller* controller;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&controller);
	ptr->DestroyController(controller);
	return_null;
}
static AS3_Val b2World_GetControllerList(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	b2Controller * controller = ptr->GetControllerList();
	return_as3_object(AS3_Val(controller->GetUserData()));
}

static AS3_Val b2World_Step(void* data, AS3_Val args)
{
	b2World* ptr;
	double timeStep;
	int32 velocityIterations;
	int32 positionIterations;
	AS3_ArrayValue(args, "PtrType,DoubleType,IntType,IntType", &ptr,&timeStep,&velocityIterations,&positionIterations);
	ptr->Step(timeStep,velocityIterations,positionIterations);
	return_null;
}
static AS3_Val b2World_ClearForces(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->ClearForces();
	return_null;
}
static AS3_Val b2World_DrawDebugData(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->DrawDebugData();
	return_null;
}
static AS3_Val b2World_QueryAABB(void * data,AS3_Val args)
{
	b2World* ptr;
	b2QueryCallback* callback;
	b2AABB * aabb;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&callback,&aabb);
	ptr->QueryAABB(callback,*aabb);
	return_null;
}
static AS3_Val b2World_RayCast(void * data,AS3_Val args)
{
	b2World* ptr;
	b2RayCastCallback* callback;
	b2Vec2* point1;
	b2Vec2* point2;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType", &ptr,&callback,&point1,&point2);
	ptr->RayCast(callback,*point1,*point2);
	return_null;
}
static AS3_Val b2World_GetBodyList(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	b2Body* body = ptr->GetBodyList();
	if(body){
		return_as3_object(AS3_Val(body->GetUserData()));
	}
	else{
		return_null;
	}
}
static AS3_Val b2World_SetGravity(void* data, AS3_Val args)
{
	b2World* ptr;
	b2Vec2 * gravity;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&gravity);
	ptr->SetGravity(*gravity);
	return_null;
}
static AS3_Val b2World_GetGravity(void* data, AS3_Val args)
{
	b2World* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(new b2Vec2(ptr->GetGravity()));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2BodyDef
static AS3_Val b2BodyDef_new(void* data, AS3_Val args)
{
	return_as3_ptr(new b2BodyDef());
}
static AS3_Val b2BodyDef_SetType(void* data, AS3_Val args)
{
	b2BodyDef* ptr;
	int type;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&type);
	ptr->type = (b2BodyType)type;
	return_null;
}
static AS3_Val b2BodyDef_GetType(void* data, AS3_Val args)
{
	b2BodyDef* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->type);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Body
static AS3_Val b2Body_CreateFixture(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2FixtureDef* def;
	AS3_Val wrap;
	AS3_ArrayValue(args, "PtrType,PtrType,AS3ValType", &ptr,&def,&wrap);
	b2Fixture * fixture = ptr->CreateFixture(def);
	fixture->SetUserData(wrap);
	return_as3_ptr(fixture);
}
static AS3_Val b2Body_CreateFixtureByShape(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Shape* shape;
	double density;
	AS3_Val wrap;
	AS3_ArrayValue(args, "PtrType,PtrType,DoubleType,AS3ValType", &ptr,&shape,&density,&wrap);
	b2Fixture * fixture = ptr->CreateFixture(shape,density);
	fixture->SetUserData(wrap);
	return_as3_ptr(fixture);
}
static AS3_Val b2Body_DestroyFixture(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Fixture * fixture;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&fixture);
	ptr->DestroyFixture(fixture);
	return_null;
}
static AS3_Val b2Body_SetTransform(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* position;
	double angle;
	AS3_ArrayValue(args, "PtrType,PtrType,DoubleType", &ptr,&position,&angle);
	ptr->SetTransform(*position,angle);
	return_null;
}
static AS3_Val b2Body_GetTransform(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((void*)&ptr->GetTransform());
}

static AS3_Val b2Body_GetPosition(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((void*)&ptr->GetPosition());
}
static AS3_Val b2Body_GetAngle(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetAngle());
}
static AS3_Val b2Body_GetWorldCenter(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((void*)&ptr->GetWorldCenter());
}
static AS3_Val b2Body_GetLocalCenter(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((void*)&ptr->GetLocalCenter());
}
static AS3_Val b2Body_SetLinearVelocity(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* v;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&v);
	ptr->SetLinearVelocity(*v);
	return_null;
}
static AS3_Val b2Body_GetLinearVelocity(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(new b2Vec2(ptr->GetLinearVelocity()));
}
static AS3_Val b2Body_SetAngularVelocity(void* data, AS3_Val args)
{
	b2Body* ptr;
	double omega;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&omega);
	ptr->SetAngularVelocity(omega);
	return_null;
}
static AS3_Val b2Body_GetAngularVelocity(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetAngularVelocity());
}
static AS3_Val b2Body_ApplyForce(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* force;
	b2Vec2* point;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&force,&point);
	ptr->ApplyForce(*force,*point);
	return_null;
}
static AS3_Val b2Body_ApplyTorque(void* data, AS3_Val args)
{
	b2Body* ptr;
	double torque;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&torque);
	ptr->ApplyTorque(torque);
	return_null;
}
static AS3_Val b2Body_ApplyLinearImpulse(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* impulse;
	b2Vec2* point;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&impulse,&point);
	ptr->ApplyLinearImpulse(*impulse,*point);
	return_null;
}
static AS3_Val b2Body_ApplyAngularImpulse(void* data, AS3_Val args)
{
	b2Body* ptr;
	double impulse;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&impulse);
	ptr->ApplyAngularImpulse(impulse);
	return_null;
}
static AS3_Val b2Body_GetMass(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetMass());
}
static AS3_Val b2Body_GetInertia(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetInertia());
}
static AS3_Val b2Body_GetMassData(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2MassData* massData;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&massData);
	ptr->GetMassData(massData);
	return_null;
}
static AS3_Val b2Body_SetMassData(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2MassData* massData;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&massData);
	ptr->SetMassData(massData);
	return_null;
}
static AS3_Val b2Body_ResetMassData(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->ResetMassData();
	return_null;
}
static AS3_Val b2Body_GetWorldPoint(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* localPoint;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&localPoint);
	return_as3_ptr(new b2Vec2(ptr->GetWorldPoint(*localPoint)));
}
static AS3_Val b2Body_GetWorldVector(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* localVector;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&localVector);
	return_as3_ptr(new b2Vec2(ptr->GetWorldVector(*localVector)));
}
static AS3_Val b2Body_GetLocalPoint(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* worldPoint;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&worldPoint);
	return_as3_ptr(new b2Vec2(ptr->GetLocalPoint(*worldPoint)));
}
static AS3_Val b2Body_GetLocalVector(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* worldVector;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&worldVector);
	return_as3_ptr(new b2Vec2(ptr->GetLocalVector(*worldVector)));
}
static AS3_Val b2Body_GetLinearVelocityFromWorldPoint(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* worldPoint;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&worldPoint);
	return_as3_ptr(new b2Vec2(ptr->GetLinearVelocityFromWorldPoint(*worldPoint)));
}
static AS3_Val b2Body_GetLinearVelocityFromLocalPoint(void* data, AS3_Val args)
{
	b2Body* ptr;
	b2Vec2* localPoint;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&localPoint);
	return_as3_ptr(new b2Vec2(ptr->GetLinearVelocityFromLocalPoint(*localPoint)));
}
static AS3_Val b2Body_GetLinearDamping(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetLinearDamping());
}
static AS3_Val b2Body_SetLinearDamping(void* data, AS3_Val args)
{
	b2Body* ptr;
	double linearDamping;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&linearDamping);
	ptr->SetLinearDamping(linearDamping);
	return_null;
}
static AS3_Val b2Body_GetAngularDamping(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetAngularDamping());
}
static AS3_Val b2Body_SetAngularDamping(void* data, AS3_Val args)
{
	b2Body* ptr;
	double angularDamping;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&angularDamping);
	ptr->SetLinearDamping(angularDamping);
	return_null;
}
static AS3_Val b2Body_SetGravityScale(void* data, AS3_Val args)
{
	b2Body* ptr;
	double scale;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&scale);
	ptr->SetGravityScale(scale);
	return_null;
}
static AS3_Val b2Body_GetGravityScale(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetGravityScale());
}
static AS3_Val b2Body_SetType(void* data, AS3_Val args)
{
	b2Body* ptr;
	int32 type;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&type);
	ptr->SetType((b2BodyType)type);
	return_null;
}
static AS3_Val b2Body_GetType(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetType());
}
static AS3_Val b2Body_SetBullet(void* data, AS3_Val args)
{
	b2Body* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->SetBullet(flag==1);
	return_null;
}
static AS3_Val b2Body_IsBullet(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsBullet()?AS3_True():AS3_False();
}
static AS3_Val b2Body_SetSleepingAllowed(void* data, AS3_Val args)
{
	b2Body* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->SetSleepingAllowed(flag==1);
	return_null;
}
static AS3_Val b2Body_IsSleepingAllowed(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsSleepingAllowed()?AS3_True():AS3_False();
}
static AS3_Val b2Body_SetAwake(void* data, AS3_Val args)
{
	b2Body* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->SetAwake(flag==1);
	return_null;
}
static AS3_Val b2Body_IsAwake (void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsAwake()?AS3_True():AS3_False();
}
static AS3_Val b2Body_SetActive(void* data, AS3_Val args)
{
	b2Body* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->SetActive(flag==1);
	return_null;
}
static AS3_Val b2Body_IsActive(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsActive()?AS3_True():AS3_False();
}
static AS3_Val b2Body_SetFixedRotation(void* data, AS3_Val args)
{
	b2Body* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->SetFixedRotation(flag==1);
	return_null;
}
static AS3_Val b2Body_IsFixedRotation(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return ptr->IsFixedRotation()?AS3_True():AS3_False();
}
static AS3_Val b2Body_GetFixtureList(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	b2Fixture* fixture = ptr->GetFixtureList();
	if(fixture){
		return_as3_object(AS3_Val(fixture->GetUserData()));
	}
	else
		return_null;
}
static AS3_Val b2Body_GetNext(void* data, AS3_Val args)
{
	b2Body* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	b2Body* body = ptr->GetNext();
	if(body){
		return_as3_object(AS3_Val(body->GetUserData()));
	}
	else
		return_null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2MassData
static AS3_Val b2MassData_new(void* data, AS3_Val args)
{
	return_as3_ptr(new b2MassData());
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Mat22
as3_new(b2Mat22)
static AS3_Val b2Mat22_Set(void* data, AS3_Val args)
{
	b2Mat22 * ptr;
	double angle;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&angle);
	ptr->Set(angle);
	return_null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Shape
static AS3_Val b2Shape_TestPoint(void* data, AS3_Val args)
{
	b2Shape* ptr;
	b2Transform * xf;
	b2Vec2* p;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&xf,&p);
	return ptr->TestPoint(*xf,*p)?AS3_True():AS3_False();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2EdgeShape
as3_new(b2EdgeShape);
static AS3_Val b2EdgeShape_Set(void* data, AS3_Val args)
{
	b2EdgeShape* ptr;
	b2Vec2 * v1;
	b2Vec2 * v2;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&v1,&v2);
	ptr->Set(*v1,*v2);
	return_null;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2CircleShape
as3_new(b2CircleShape)


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2PolygonShape
as3_new(b2PolygonShape)
static AS3_Val b2PolygonShape_Set(void* data, AS3_Val args)
{
	b2PolygonShape* ptr;
	b2Vec2 * vertices;
	int vertexCount;
	AS3_ArrayValue(args, "PtrType,PtrType,IntType", &ptr,&vertices,&vertexCount);
	ptr->Set(vertices,vertexCount);
	return_null;
}
static AS3_Val b2PolygonShape_SetAsBox(void* data, AS3_Val args)
{
	b2PolygonShape* ptr;
	double hx;
	double hy;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType", &ptr,&hx,&hy);
	ptr->SetAsBox(hx,hy);
	return_null;
}
static AS3_Val b2PolygonShape_SetAsBoxByCenter(void* data, AS3_Val args)
{
	b2PolygonShape* ptr;
	double hx;
	double hy;
	b2Vec2* center;
	double angle;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType,PtrType,DoubleType", &ptr,&hx,&hy,&center,&angle);
	ptr->SetAsBox(hx,hy,*center,angle);
	return_null;
}
static AS3_Val b2PolygonShape_GetVertexCount(void* data, AS3_Val args)
{
	b2PolygonShape* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetVertexCount());
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2LoopShape
as3_new(b2LoopShape);
static AS3_Val b2LoopShape_Set(void* data, AS3_Val args)
{
	b2LoopShape* ptr;
	b2Vec2* vertices;
	int count;
	AS3_ArrayValue(args, "PtrType,PtrType,IntType", &ptr,&vertices,&count);
	ptr->Create(vertices,count);
	return_null;
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Fixture
static AS3_Val b2Fixture_GetType(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetType());
}
static AS3_Val b2Fixture_GetShape(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(ptr->GetShape());
}
static AS3_Val b2Fixture_SetSensor(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	int sensor;
	AS3_ArrayValue(args, "PtrType,IntPtr", &ptr,&sensor);
	ptr->SetSensor(sensor==1);
	return_null;
}
static AS3_Val b2Fixture_IsSensor(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	if(ptr->IsSensor())
		return AS3_True();
	else
		return AS3_False();
}
static AS3_Val b2Fixture_SetFilterData(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	b2Filter* filter;
	AS3_ArrayValue(args, "PtrType,PtrPtr", &ptr,&filter);
	ptr->SetFilterData(*filter);
	return_null;
}
static AS3_Val b2Fixture_GetFilterData(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((b2Filter*)&ptr->GetFilterData());
}
static AS3_Val b2Fixture_GetBody(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_object(AS3_Val(ptr->GetBody()->GetUserData()));
}
static AS3_Val b2Fixture_GetNext(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_object(AS3_Val(ptr->GetNext()->GetUserData()));
}
static AS3_Val b2Fixture_TestPoint(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	b2Vec2 * p;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&p);
	return ptr->TestPoint(*p)?AS3_True():AS3_False();
}

static AS3_Val b2Fixture_GetMassData(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	b2MassData * massData;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&massData);
	ptr->GetMassData(massData);
	return_null;
}
static AS3_Val b2Fixture_SetDensity(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	double value;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&value);
	ptr->SetDensity(value);
	return_null;
}
static AS3_Val b2Fixture_GetDensity(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetDensity());
}
static AS3_Val b2Fixture_GetFriction(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetFriction());
}
static AS3_Val b2Fixture_SetFriction(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	double value;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&value);
	ptr->SetFriction(value);
	return_null;
}
static AS3_Val b2Fixture_GetRestitution(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetRestitution());
}
static AS3_Val b2Fixture_SetRestitution(void* data, AS3_Val args)
{
	b2Fixture* ptr;
	double value;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&value);
	ptr->SetRestitution(value);
	return_null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2FixtureDef
static AS3_Val b2FixtureDef_new(void* data, AS3_Val args)
{
	return_as3_ptr(new b2FixtureDef());
}
static AS3_Val b2FixtureDef_SetShape(void* data, AS3_Val args)
{
	b2FixtureDef* ptr;
	b2Shape* shape;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&shape);
	ptr->shape = shape;
	return_null;
}
static AS3_Val b2FixtureDef_GetShape(void* data, AS3_Val args)
{
	b2FixtureDef* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr((b2Shape*)ptr->shape);
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Draw
static AS3_Val b2Draw_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2DrawWrap(wrap));
}
static AS3_Val b2Draw_SetFlags(void* data, AS3_Val args)
{
	b2Draw* ptr;
	int flags;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flags);
	ptr->SetFlags(flags);
	return_null;
}
static AS3_Val b2Draw_GetFlags(void* data, AS3_Val args)
{
	b2Draw* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetFlags());
}
static AS3_Val b2Draw_AppendFlags(void* data, AS3_Val args)
{
	b2Draw* ptr;
	int flags;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flags);
	ptr->AppendFlags(flags);
	return_null;
}
static AS3_Val b2Draw_ClearFlags(void* data, AS3_Val args)
{
	b2Draw* ptr;
	int flags;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flags);
	ptr->ClearFlags(flags);
	return_null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2DestructionListener
static AS3_Val b2DestructionListener_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2DestructionListenerWrap(wrap));
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2ContactListener
static AS3_Val b2ContactListener_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2ContactListenerWrap(wrap));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2WorldManifold
as3_new(b2WorldManifold)
static AS3_Val b2WorldManifold_Initialize(void* data, AS3_Val args)
{
	b2WorldManifold * ptr;
	b2Manifold * manifold;
	b2Transform * xfA;
	double radiusA;
	b2Transform* xfB;
	double radiusB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,DoubleType,PtrType,DoubleType", &ptr,&manifold,&xfA,&radiusA,&xfB,&radiusB);
	ptr->Initialize(manifold,*xfA,radiusA,*xfB,radiusB);
	return_null;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Contact
static AS3_Val b2Contact_GetManifold(void* data, AS3_Val args)
{
	b2Contact * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(ptr->GetManifold());
}
static AS3_Val b2Contact_GetWorldManifold(void* data, AS3_Val args)
{
	b2Contact * ptr;
	b2WorldManifold * worldManifold;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&worldManifold);
	ptr->GetWorldManifold(worldManifold);
	return_null;
}
static AS3_Val b2Contact_GetFixtureA(void* data, AS3_Val args)
{
	b2Contact * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_object(AS3_Val(ptr->GetFixtureA()->GetUserData()));
}
static AS3_Val b2Contact_GetFixtureB(void* data, AS3_Val args)
{
	b2Contact * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_object(AS3_Val(ptr->GetFixtureB()->GetUserData()));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2ContactFilter 
static AS3_Val b2ContactFilter_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2ContactFilterWrap(wrap));
}
static AS3_Val b2ContactFilter_ShouldCollide(void* data, AS3_Val args)
{
	b2ContactFilterWrap* ptr;
	b2Fixture * fixtureA;
	b2Fixture * fixtureB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &ptr,&fixtureA,&fixtureB);
	return ptr->CallSuperShouldCollide(fixtureA,fixtureB)?AS3_True():AS3_False();
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Controller
as3_new(b2BuoyancyControllerDef);
as3_new(b2ConstantAccelControllerDef);
as3_new(b2ConstantForceControllerDef);
as3_new(b2GravityControllerDef);
as3_new(b2TensorDampingControllerDef);
static AS3_Val b2CustomControllerDef_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2CustomControllerDef(wrap));
}
static AS3_Val b2Controller_AddBody(void* data, AS3_Val args)
{
	b2Controller * ptr;
	b2Body* body;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&body);	
	ptr->AddBody(body);
	return_null;
}
static AS3_Val b2Controller_RemoveBody(void* data, AS3_Val args)
{
	b2Controller * ptr;
	b2Body* body;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&body);	
	ptr->RemoveBody(body);
	return_null;
}
static AS3_Val b2Controller_Clear(void* data, AS3_Val args)
{
	b2Controller * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	ptr->Clear();
	return_null;
}
static AS3_Val b2Controller_GetType(void* data, AS3_Val args)
{
	b2Controller * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	return AS3_Int(ptr->GetType());
}
static AS3_Val b2Controller_GetNext(void* data, AS3_Val args)
{
	b2Controller * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	b2Controller* controller = ptr->GetNext();
	if(controller){
		return_as3_object(AS3_Val(controller->GetUserData()));
	}
	else
		return_null;
}
static AS3_Val b2Controller_GetBodyList(void* data, AS3_Val args)
{
	b2Controller * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	return_as3_ptr(ptr->GetBodyList());
}
static AS3_Val b2CustomController_GetDef(void* data, AS3_Val args)
{
	b2CustomController * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	return_as3_object(ptr->getDefWrap());
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2ControllerEdge
static AS3_Val b2ControllerEdge_GetBody(void* data, AS3_Val args)
{
	b2ControllerEdge * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_object(AS3_Val(ptr->body->GetUserData()));
}
static AS3_Val b2ControllerEdge_GetController(void* data, AS3_Val args)
{
	b2ControllerEdge * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);	
	return_as3_object(AS3_Val(ptr->controller->GetUserData()));
}

as3_new(b2RayCastInput)
as3_new(b2RayCastOutput)

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2QueryCallback
static AS3_Val b2QueryCallback_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2QueryCallbackWrap(wrap));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2RayCastCallback
static AS3_Val b2RayCastCallback_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2RayCastCallbackWrap(wrap));
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2Joint
static AS3_Val b2Joint_GetAnchorA(void* data, AS3_Val args)
{
	b2Joint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(new b2Vec2(ptr->GetAnchorA()));
}
static AS3_Val b2Joint_GetAnchorB(void* data, AS3_Val args)
{
	b2Joint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(new b2Vec2(ptr->GetAnchorB()));
}
static AS3_Val b2Joint_GetReactionForce(void* data, AS3_Val args)
{
	b2Joint* ptr;
	double inv_dt;
	AS3_ArrayValue(args, "PtrType", &ptr,&inv_dt);
	return_as3_ptr(new b2Vec2(ptr->GetReactionForce(inv_dt)));
}
static AS3_Val b2Joint_GetReactionTorque(void* data, AS3_Val args)
{
	b2Joint* ptr;
	double inv_dt;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&inv_dt);
	return AS3_Number(ptr->GetReactionTorque(inv_dt));
}


as3_new(b2MouseJointDef);
static AS3_Val b2MouseJoint_SetTarget(void* data, AS3_Val args)
{
	b2MouseJoint* ptr;
	b2Vec2* p;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&p);
	ptr->SetTarget(*p);
	return_null;
}
static AS3_Val b2MouseJoint_GetTarget(void* data, AS3_Val args)
{
	b2MouseJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_as3_ptr(new b2Vec2(ptr->GetTarget()));
}

as3_new(b2DistanceJointDef);
static AS3_Val b2DistanceJointDef_Initialize(void* data, AS3_Val args)
{
	b2DistanceJointDef* ptr;
	b2Body* bodyA;
	b2Body* bodyB;
	b2Vec2* anchorA;
	b2Vec2* anchorB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &ptr,&bodyA,&bodyB,&anchorA,&anchorB);
	ptr->Initialize(bodyA,bodyB,*anchorA,*anchorB);
	return_null;
}


as3_new(b2FrictionJointDef);

as3_new(b2PrismaticJointDef);
static AS3_Val b2PrismaticJointDef_Initialize(void* data, AS3_Val args)
{
	b2PrismaticJointDef* ptr;
	b2Body* bodyA;
	b2Body* bodyB;
	b2Vec2* anchor;
	b2Vec2* axis;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &ptr,&bodyA,&bodyB,&anchor,&axis);
	ptr->Initialize(bodyA,bodyB,*anchor,*axis);
	return_null;
}
static AS3_Val b2PrismaticJoint_GetJointTranslation(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointTranslation());
}
static AS3_Val b2PrismaticJoint_GetJointSpeed(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointSpeed());
}
static AS3_Val b2PrismaticJoint_IsLimitEnabled(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_bool(ptr->IsLimitEnabled());
}
static AS3_Val b2PrismaticJoint_EnableLimit(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->EnableLimit(1==flag);
	return_null;
}
static AS3_Val b2PrismaticJoint_GetLowerLimit(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetLowerLimit());
}
static AS3_Val b2PrismaticJoint_GetUpperLimit(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetUpperLimit());
}
static AS3_Val b2PrismaticJoint_SetLimits(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	double lower;
	double upper;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType", &ptr,&lower,&upper);
	ptr->SetLimits(lower,upper);
	return_null;
}
static AS3_Val b2PrismaticJoint_IsMotorEnabled(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_bool(ptr->IsMotorEnabled());
}
static AS3_Val b2PrismaticJoint_EnableMotor(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->EnableMotor(1==flag);
	return_null;
}
static AS3_Val b2PrismaticJoint_SetMotorSpeed(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	double speed;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&speed);
	ptr->SetMotorSpeed(speed);
	return_null;
}
static AS3_Val b2PrismaticJoint_GetMotorSpeed(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetMotorSpeed());
}
static AS3_Val b2PrismaticJoint_SetMaxMotorForce(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	double force;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&force);
	ptr->SetMaxMotorForce(force);
	return_null;
}
static AS3_Val b2PrismaticJoint_GetMotorForce(void* data, AS3_Val args)
{
	b2PrismaticJoint* ptr;
	double inv_dt;
	AS3_ArrayValue(args, "PtrType", &ptr,&inv_dt);
	return AS3_Number(ptr->GetMotorForce(inv_dt));
}


as3_new(b2RevoluteJointDef);
static AS3_Val b2RevoluteJointDef_Initialize(void* data, AS3_Val args)
{
	b2RevoluteJointDef* ptr;
	b2Body* bodyA;
	b2Body* bodyB;
	b2Vec2* anchor;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType", &ptr,&bodyA,&bodyB,&anchor);
	ptr->Initialize(bodyA,bodyB,*anchor);
	return_null;
}
static AS3_Val b2RevoluteJoint_GetJointAngle(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointAngle());
}
static AS3_Val b2RevoluteJoint_GetJointSpeed(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointSpeed());
}
static AS3_Val b2RevoluteJoint_IsLimitEnabled(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_bool(ptr->IsLimitEnabled());
}
static AS3_Val b2RevoluteJoint_EnableLimit(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->EnableLimit(1==flag);
	return_null;
}
static AS3_Val b2RevoluteJoint_GetLowerLimit(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetLowerLimit());
}
static AS3_Val b2RevoluteJoint_GetUpperLimit(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetUpperLimit());
}
static AS3_Val b2RevoluteJoint_SetLimits(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	double lower;
	double upper;
	AS3_ArrayValue(args, "PtrType,DoubleType,DoubleType", &ptr,&lower,&upper);
	ptr->SetLimits(lower,upper);
	return_null;
}
static AS3_Val b2RevoluteJoint_IsMotorEnabled(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_bool(ptr->IsMotorEnabled());
}
static AS3_Val b2RevoluteJoint_EnableMotor(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->EnableMotor(1==flag);
	return_null;
}
static AS3_Val b2RevoluteJoint_SetMotorSpeed(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	double speed;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&speed);
	ptr->SetMotorSpeed(speed);
	return_null;
}
static AS3_Val b2RevoluteJoint_GetMotorSpeed(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetMotorSpeed());
}
static AS3_Val b2RevoluteJoint_SetMaxMotorTorque(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	double torque;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&torque);
	ptr->SetMaxMotorTorque(torque);
	return_null;
}
static AS3_Val b2RevoluteJoint_GetMotorTorque(void* data, AS3_Val args)
{
	b2RevoluteJoint* ptr;
	double inv_dt;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&inv_dt);
	return AS3_Number(ptr->GetMotorTorque(inv_dt));
}

as3_new(b2GearJointDef);
static AS3_Val b2GearJoint_SetRatio(void* data, AS3_Val args)
{
	b2GearJoint* ptr;
	double ratio;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&ratio);
	ptr->SetRatio(ratio);
	return_null;
}
static AS3_Val b2GearJoint_GetRatio(void* data, AS3_Val args)
{
	b2GearJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetRatio());
}
as3_new(b2WeldJointDef);
static AS3_Val b2WeldJointDef_Initialize(void* data, AS3_Val args)
{
	b2WeldJointDef* ptr;
	b2Body* body1;
	b2Body* body2;
	b2Vec2* anchor;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType", &ptr,&body1,&body2,&anchor);
	ptr->Initialize(body1,body2,*anchor);
	return_null;
}
as3_new(b2WheelJointDef);
static AS3_Val b2WheelJointDef_Initialize(void* data, AS3_Val args)
{
	b2WheelJointDef* ptr;
	b2Body* bodyA;
	b2Body* bodyB;
	b2Vec2* anchor;
	b2Vec2* axis;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &ptr,&bodyA,&bodyB,&anchor,&axis);
	ptr->Initialize(bodyA,bodyB,*anchor,*axis);
	return_null;
}
static AS3_Val b2WheelJoint_GetJointTranslation(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointTranslation());
}
static AS3_Val b2WheelJoint_GetJointSpeed(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetJointSpeed());
}
static AS3_Val b2WheelJoint_IsMotorEnabled(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return_bool(ptr->IsMotorEnabled());
}
static AS3_Val b2WheelJoint_EnableMotor(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	int flag;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&flag);
	ptr->EnableMotor(1==flag);
	return_null;
}
static AS3_Val b2WheelJoint_SetMotorSpeed(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	double speed;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&speed);
	ptr->SetMotorSpeed(speed);
	return_null;
}
static AS3_Val b2WheelJoint_GetMotorSpeed(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetMotorSpeed());
}
static AS3_Val b2WheelJoint_SetMaxMotorTorque(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	double torque;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&torque);
	ptr->SetMaxMotorTorque(torque);
	return_null;
}
static AS3_Val b2WheelJoint_GetMaxMotorTorque(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetMaxMotorTorque());
}
static AS3_Val b2WheelJoint_GetMotorTorque(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	double inv_dt;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&inv_dt);
	return AS3_Number(ptr->GetMotorTorque(inv_dt));
}
static AS3_Val b2WheelJoint_SetSpringFrequencyHz(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	double hz;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&hz);
	ptr->SetSpringFrequencyHz(hz);
	return_null;
}
static AS3_Val b2WheelJoint_GetSpringFrequencyHz(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetSpringFrequencyHz());
}
static AS3_Val b2WheelJoint_SetSpringDampingRatio(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	double ratio;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&ratio);
	ptr->SetSpringDampingRatio(ratio);
	return_null;
}
static AS3_Val b2WheelJoint_GetSpringDampingRatio(void* data, AS3_Val args)
{
	b2WheelJoint* ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetSpringDampingRatio());
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// b2DynamicTree
static AS3_Val b2DynamicTree_new(void* data, AS3_Val args)
{
	AS3_Val wrap;
	AS3_ArrayValue(args, "AS3ValType", &wrap);
	return_as3_ptr(new b2DynamicTreeWrap(wrap));
}
static AS3_Val b2DynamicTree_CreateProxy(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	b2AABB* aabb;
	AS3_Val userData;
	AS3_ArrayValue(args, "PtrType,PtrType,AS3ValType", &ptr,&aabb,&userData);
	return AS3_Int(ptr->CreateProxy(*aabb,userData));
}
static AS3_Val b2DynamicTree_DestroyProxy(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	int proxyId;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&proxyId);
	ptr->DestroyProxy(proxyId);
	return_null;
}
static AS3_Val b2DynamicTree_MoveProxy(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	int proxyId;
	b2AABB* aabb1;
	b2Vec2* displacement;
	AS3_ArrayValue(args, "PtrType,IntType,PtrType,PtrType", &ptr,&proxyId,&aabb1,&displacement);
	return_bool(ptr->MoveProxy(proxyId,*aabb1,*displacement));
}
static AS3_Val b2DynamicTree_GetUserData(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	int proxyId;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&proxyId);
	return_as3_object(AS3_Val(ptr->GetUserData(proxyId)));
}
static AS3_Val b2DynamicTree_GetFatAABB(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	int proxyId;
	AS3_ArrayValue(args, "PtrType,IntType", &ptr,&proxyId);
	return_as3_ptr(new b2AABB(ptr->GetFatAABB(proxyId)));
}
static AS3_Val b2DynamicTree_Query(void* data, AS3_Val args)
{
	b2DynamicTreeWrap * ptr;
	b2AABB * aabb;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&aabb);
	ptr->Query(ptr,*aabb);
	return_null;
}
static AS3_Val b2DynamicTree_RayCast(void* data, AS3_Val args)
{
	b2DynamicTreeWrap * ptr;
	b2RayCastInput*	input;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&input);
	ptr->RayCast(ptr,*input);
	return_null;
}
static AS3_Val b2DynamicTree_Validate(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->Validate();
	return_null;
}
static AS3_Val b2DynamicTree_GetHeight(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetHeight());
}
static AS3_Val b2DynamicTree_GetMaxBalance(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetMaxBalance());
}
static AS3_Val b2DynamicTree_GetAreaRatio(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetAreaRatio());
}
static AS3_Val b2DynamicTree_RebuildBottomUp(void* data, AS3_Val args)
{
	b2DynamicTree * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->RebuildBottomUp();
	return_null;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Math
as3_new(b2Manifold);
as3_new(b2Transform)
static AS3_Val b2Transform_Copy(void* data, AS3_Val args)
{
	b2Transform * ptr;
	b2Transform * source;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&source);
	*ptr = *source;
	return_null;
}
static AS3_Val b2Transform_SetIdentity(void* data, AS3_Val args)
{
	b2Transform * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->SetIdentity();
	return_null;
}
static AS3_Val b2Transform_Set(void* data, AS3_Val args)
{
	b2Transform * ptr;
	b2Vec2* p;
	double angle;
	AS3_ArrayValue(args, "PtrType,PtrType,DoubleType", &ptr,&p,&angle);
	ptr->Set(*p,angle);
	return_null;
}
static AS3_Val b2Transform_GetAngle(void* data, AS3_Val args)
{
	b2Transform * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Number(ptr->GetAngle());
}

as3_new(b2Sweep);
static AS3_Val b2Sweep_GetTransform(void* data, AS3_Val args)
{
	b2Sweep * ptr;
	b2Transform* xf;
	double beta;
	AS3_ArrayValue(args, "PtrType,PtrType,DoubleType", &ptr,&xf,&beta);
	ptr->GetTransform(xf,beta);
	return_null;
}
static AS3_Val b2Sweep_Advance(void* data, AS3_Val args)
{
	b2Sweep * ptr;
	double alpha;
	AS3_ArrayValue(args, "PtrType,DoubleType", &ptr,&alpha);
	ptr->Advance(alpha);
	return_null;
}
static AS3_Val b2Sweep_Normalize(void* data, AS3_Val args)
{
	b2Sweep * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	ptr->Normalize();
	return_null;
}
static AS3_Val b2Sweep_Copy(void* data, AS3_Val args)
{
	b2Sweep * ptr;
	b2Sweep * source;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&source);
	*ptr = *source;
	return_null;
}
as3_new(b2DistanceInput);
as3_new(b2DistanceOutput);
as3_new(b2SimplexCache);
as3_new(b2TOIInput);
as3_new(b2TOIOutput);
static AS3_Val b2TimeOfImpact_TimeOfImpact(void* data, AS3_Val args)
{
	b2TOIOutput * output;
	b2TOIInput * input;
	AS3_ArrayValue(args, "PtrType,PtrType", &output,&input);
	b2TimeOfImpact(output,input);
	return_null;
}
static AS3_Val b2DistanceProxy_Set(void* data, AS3_Val args)
{
	b2DistanceProxy * ptr;
	b2Shape* shape;
	int index;
	AS3_ArrayValue(args, "PtrType,PtrType,IntType", &ptr,&shape,&index);
	ptr->Set(shape,index);
	return_null;
}
static AS3_Val b2DistanceProxy_GetSupport(void* data, AS3_Val args)
{
	b2DistanceProxy * ptr;
	b2Vec2 * d;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&d);
	return AS3_Int(ptr->GetSupport(*d));
}
static AS3_Val b2DistanceProxy_GetSupportVertex(void* data, AS3_Val args)
{
	b2DistanceProxy * ptr;
	b2Vec2 * d;
	AS3_ArrayValue(args, "PtrType,PtrType", &ptr,&d);
	return_as3_ptr(new b2Vec2(ptr->GetSupportVertex(*d)));
}
static AS3_Val b2DistanceProxy_GetVertexCount(void* data, AS3_Val args)
{
	b2DistanceProxy * ptr;
	AS3_ArrayValue(args, "PtrType", &ptr);
	return AS3_Int(ptr->GetVertexCount());
}
static AS3_Val b2DistanceProxy_GetVertex(void* data, AS3_Val args)
{
	b2DistanceProxy * ptr;
	int index;
	AS3_ArrayValue(args, "PtrType", &ptr,&index);
	return_as3_ptr(new b2Vec2(ptr->GetVertex(index)));
}
static AS3_Val b2Distance_Distance(void* data, AS3_Val args)
{
	b2DistanceOutput * output;
	b2SimplexCache * cache;
	b2DistanceInput * input;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &output,&cache,&input);
	b2Distance(output,cache,input);
	return_null;
}

static AS3_Val b2Math_MulX(void* data, AS3_Val args)
{
	b2Transform* T;
	b2Vec2* v;
	AS3_ArrayValue(args, "PtrType,PtrType", &T,&v);
	return_as3_ptr(new b2Vec2(b2Mul(*T,*v)));
}
static AS3_Val b2Math_MulXT(void* data, AS3_Val args)
{
	b2Transform* T;
	b2Vec2* v;
	AS3_ArrayValue(args, "PtrType,PtrType", &T,&v);
	return_as3_ptr(new b2Vec2(b2MulT(*T,*v)));
}
static AS3_Val b2Math_MulA(void* data, AS3_Val args)
{
	b2Mat22 * A;
	b2Vec2* v;
	AS3_ArrayValue(args, "PtrType,PtrType", &A,&v);
	return_as3_ptr(new b2Vec2(b2Mul(*A,*v)));
}
static AS3_Val b2Math_MulAT(void* data, AS3_Val args)
{
	b2Mat22 * A;
	b2Vec2* v;
	AS3_ArrayValue(args, "PtrType,PtrType", &A,&v);
	return_as3_ptr(new b2Vec2(b2MulT(*A,*v)));
}
static AS3_Val b2Math_Clamp(void* data, AS3_Val args)
{
	b2Vec2* a;
	b2Vec2* low;
	b2Vec2* high;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType", &a,&low,&high);
	return_as3_ptr(new b2Vec2(b2Clamp(*a,*low,*high)));
}
static AS3_Val b2Math_CrossVV(void* data, AS3_Val args)
{
	b2Vec2* a;
	b2Vec2* b;
	AS3_ArrayValue(args, "PtrType,PtrType", &a,&b);
	return AS3_Number(b2Cross(*a,*b));
}
static AS3_Val b2Math_CrossVF(void* data, AS3_Val args)
{
	b2Vec2* a;
	double s;
	AS3_ArrayValue(args, "PtrType,DoubleType", &a,&s);
	return_as3_ptr(new b2Vec2(b2Cross(*a,s)));
}
static AS3_Val b2Math_CrossFV(void* data, AS3_Val args)
{
	double s;
	b2Vec2* a;
	AS3_ArrayValue(args, "DoubleType,PtrType", &s,&a);
	return_as3_ptr(new b2Vec2(b2Cross(s,*a)));
}
static AS3_Val b2Math_CrossV3(void* data, AS3_Val args)
{
	b2Vec3* a;
	b2Vec3* b;
	AS3_ArrayValue(args, "PtrType,PtrType", &a,&b);
	return_as3_ptr(new b2Vec3(b2Cross(*a,*b)));
}

static AS3_Val b2Collision_CollideCircles(void* data, AS3_Val args)
{
	b2Manifold* manifold;
	b2CircleShape* circleA;
	b2Transform* xfA;
	b2CircleShape* circleB;
	b2Transform* xfB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &manifold,&circleA,&xfA,&circleB,&xfB);
	b2CollideCircles(manifold,circleA,*xfA,circleB,*xfB);
	return_null;
}
static AS3_Val b2Collision_CollidePolygonAndCircle(void* data, AS3_Val args)
{
	b2Manifold* manifold;
	b2PolygonShape* polygonA;
	b2Transform* xfA;
	b2CircleShape* circleB;
	b2Transform* xfB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &manifold,&polygonA,&xfA,&circleB,&xfB);
	b2CollidePolygonAndCircle(manifold,polygonA,*xfA,circleB,*xfB);
	return_null;
}
static AS3_Val b2Collision_CollidePolygons(void* data, AS3_Val args)
{
	b2Manifold* manifold;
	b2PolygonShape* polygonA;
	b2Transform* xfA;
	b2PolygonShape* polygonB;
	b2Transform* xfB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &manifold,&polygonA,&xfA,&polygonB,&xfB);
	b2CollidePolygons(manifold,polygonA,*xfA,polygonB,*xfB);
	return_null;
}
static AS3_Val b2Collision_CollideEdgeAndCircle(void* data, AS3_Val args)
{
	b2Manifold* manifold;
	b2EdgeShape* edgeA;
	b2Transform* xfA;
	b2CircleShape* circleB;
	b2Transform* xfB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &manifold,&edgeA,&xfA,&circleB,&xfB);
	b2CollideEdgeAndCircle(manifold,edgeA,*xfA,circleB,*xfB);
	return_null;
}
static AS3_Val b2Collision_CollideEdgeAndPolygon(void* data, AS3_Val args)
{
	b2Manifold* manifold;
	b2EdgeShape* edgeA;
	b2Transform* xfA;
	b2PolygonShape* polygonB;
	b2Transform* xfB;
	AS3_ArrayValue(args, "PtrType,PtrType,PtrType,PtrType,PtrType", &manifold,&edgeA,&xfA,&polygonB,&xfB);
	b2CollideEdgeAndPolygon(manifold,edgeA,*xfA,polygonB,*xfB);
	return_null;
}
static AS3_Val b2Collision_TestOverlap(void* data, AS3_Val args)
{
	b2AABB* a;
	b2AABB* b;
	AS3_ArrayValue(args, "PtrType,PtrType", &a,&b);
	return_bool(b2TestOverlap(*a,*b));
}

static AS3_Val b2_gjkCalls_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_gjkCalls);
}
static AS3_Val b2_gjkCalls_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_gjkCalls = value;
	return_null;
}
static AS3_Val b2_gjkIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_gjkIters);
}
static AS3_Val b2_gjkIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_gjkIters = value;
	return_null;
}
static AS3_Val b2_gjkMaxIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_gjkMaxIters);
}
static AS3_Val b2_gjkMaxIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_gjkMaxIters = value;
	return_null;
}
static AS3_Val b2_toiCalls_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_toiCalls);
}
static AS3_Val b2_toiCalls_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_toiCalls = value;
	return_null;
}
static AS3_Val b2_toiIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_toiIters);
}
static AS3_Val b2_toiIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_toiIters = value;
	return_null;
}
static AS3_Val b2_toiMaxIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_toiMaxIters);
}
static AS3_Val b2_toiMaxIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_toiMaxIters = value;
	return_null;
}
static AS3_Val b2_toiRootIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_toiRootIters);
}
static AS3_Val b2_toiRootIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_toiRootIters = value;
	return_null;
}
static AS3_Val b2_toiMaxRootIters_get(void* data,AS3_Val args)
{
	return AS3_Int(b2_toiMaxRootIters);
}
static AS3_Val b2_toiMaxRootIters_set(void* data,AS3_Val args)
{
	int value;
	AS3_ArrayValue(args, "IntType", &value);
	b2_toiMaxRootIters = value;
	return_null;
}
static AS3_Val b2_version_get(void* data,AS3_Val args)
{
	return_as3_ptr(new b2Version(b2_version));
}

AS3_Val b2Core() { 
	return AS3_Object(
			"b2AABB_new:AS3ValType"
			",b2AABB_Copy:AS3ValType"
			",b2AABB_GetCenter:AS3ValType"
			",b2AABB_GetExtents:AS3ValType"
			",b2AABB_Combine:AS3ValType"
			",b2AABB_Contains:AS3ValType"
			",b2AABB_RayCast:AS3ValType"

			",b2Color_new:AS3ValType"
			",b2Color_Set:AS3ValType"

			",b2Vec2_new:AS3ValType"
			",b2Vec2_Array_new:AS3ValType"
			",b2Vec2_SetZero:AS3ValType"
			",b2Vec2_Set:AS3ValType"
			",b2Vec2_Length:AS3ValType"
			",b2Vec2_LengthSquared:AS3ValType"
			",b2Vec2_Normalize:AS3ValType"
			",b2Vec2_IsValid:AS3ValType"

			",b2Vec3_new:AS3ValType"

			",b2World_new:AS3ValType"
			",b2World_delete:AS3ValType"
			",b2World_SetDestructionListener:AS3ValType"
			",b2World_SetContactFilter:AS3ValType"
			",b2World_GetContactFilter:AS3ValType"
			",b2World_SetContactListener:AS3ValType"
			",b2World_SetDebugDraw:AS3ValType"
			",b2World_CreateBody:AS3ValType"
			",b2World_DestroyBody:AS3ValType"
			",b2World_CreateJoint:AS3ValType"
			",b2World_DestroyJoint:AS3ValType"
			",b2World_CreateController:AS3ValType"
			",b2World_DestroyController:AS3ValType"
			",b2World_GetControllerList:AS3ValType"
			",b2World_Step:AS3ValType"
			",b2World_ClearForces:AS3ValType"
			",b2World_DrawDebugData:AS3ValType"
			",b2World_QueryAABB:AS3ValType"
			",b2World_RayCast:AS3ValType"
			",b2World_GetBodyList:AS3ValType"
			",b2World_SetGravity:AS3ValType"
			",b2World_GetGravity:AS3ValType"

			",b2BodyDef_new:AS3ValType"
			",b2BodyDef_SetType:AS3ValType"
			",b2BodyDef_GetType:AS3ValType"

			",b2Body_CreateFixture:AS3ValType"
			",b2Body_CreateFixtureByShape:AS3ValType"
			",b2Body_DestroyFixture:AS3ValType"
			",b2Body_SetTransform:AS3ValType"
			",b2Body_GetTransform:AS3ValType"
			",b2Body_GetPosition:AS3ValType"
			",b2Body_GetAngle:AS3ValType"
			",b2Body_GetWorldCenter:AS3ValType"
			",b2Body_GetLocalCenter:AS3ValType"
			",b2Body_SetLinearVelocity:AS3ValType"
			",b2Body_GetLinearVelocity:AS3ValType"
			",b2Body_SetAngularVelocity:AS3ValType"
			",b2Body_GetAngularVelocity:AS3ValType"
			",b2Body_ApplyForce:AS3ValType"
			",b2Body_ApplyTorque:AS3ValType"
			",b2Body_ApplyLinearImpulse:AS3ValType"
			",b2Body_ApplyAngularImpulse:AS3ValType"
			",b2Body_GetMass:AS3ValType"
			",b2Body_GetInertia:AS3ValType"
			",b2Body_GetMassData:AS3ValType"
			",b2Body_SetMassData:AS3ValType"
			",b2Body_ResetMassData:AS3ValType"
			",b2Body_GetWorldPoint:AS3ValType"
			",b2Body_GetWorldVector:AS3ValType"
			",b2Body_GetLocalPoint:AS3ValType"
			",b2Body_GetLocalVector:AS3ValType"
			",b2Body_GetLinearVelocityFromWorldPoint:AS3ValType"
			",b2Body_GetLinearVelocityFromLocalPoint:AS3ValType"
			",b2Body_GetLinearDamping:AS3ValType"
			",b2Body_SetLinearDamping:AS3ValType"
			",b2Body_GetAngularDamping:AS3ValType"
			",b2Body_SetAngularDamping:AS3ValType"
			",b2Body_SetGravityScale:AS3ValType"
			",b2Body_GetGravityScale:AS3ValType"
			",b2Body_SetType:AS3ValType"
			",b2Body_GetType:AS3ValType"
			",b2Body_SetBullet:AS3ValType"
			",b2Body_IsBullet:AS3ValType"
			",b2Body_SetSleepingAllowed:AS3ValType"
			",b2Body_IsSleepingAllowed:AS3ValType"
			",b2Body_SetAwake:AS3ValType"
			",b2Body_IsAwake:AS3ValType"
			",b2Body_SetActive:AS3ValType"
			",b2Body_IsActive:AS3ValType"
			",b2Body_SetFixedRotation:AS3ValType"
			",b2Body_IsFixedRotation:AS3ValType"
			",b2Body_GetFixtureList:AS3ValType"
//			",b2Body_GetJointList:AS3ValType"
//			",b2Body_GetContactList:AS3ValType"
			",b2Body_GetNext:AS3ValType"
//			",b2Body_GetUserData:AS3ValType"
//			",b2Body_SetUserData:AS3ValType"
//			",b2Body_GetWorld:AS3ValType"

			",b2MassData_new:AS3ValType"

			",b2Mat22_new:AS3ValType"
			",b2Mat22_Set:AS3ValType"

			",b2Shape_TestPoint:AS3ValType"

			",b2EdgeShape_new:AS3ValType"
			",b2EdgeShape_Set:AS3ValType"

			",b2CircleShape_new:AS3ValType"

			",b2PolygonShape_new:AS3ValType"
			",b2PolygonShape_Set:AS3ValType"
			",b2PolygonShape_SetAsBox:AS3ValType"
			",b2PolygonShape_SetAsBoxByCenter:AS3ValType"
			",b2PolygonShape_GetVertexCount:AS3ValType"

			",b2LoopShape_new:AS3ValType"
			",b2LoopShape_Create:AS3ValType"


			",b2Fixture_GetType:AS3ValType"
			",b2Fixture_GetShape:AS3ValType"
			",b2Fixture_SetSensor:AS3ValType"
			",b2Fixture_IsSensor:AS3ValType"
			",b2Fixture_SetFilterData:AS3ValType"
			",b2Fixture_GetFilterData:AS3ValType"
			",b2Fixture_GetBody:AS3ValType"
			",b2Fixture_GetNext:AS3ValType"
			",b2Fixture_TestPoint:AS3ValType"
			",b2Fixture_GetMassData:AS3ValType"
			",b2Fixture_SetDensity:AS3ValType"
			",b2Fixture_GetDensity:AS3ValType"
			",b2Fixture_GetFriction:AS3ValType"
			",b2Fixture_SetFriction:AS3ValType"
			",b2Fixture_GetRestitution:AS3ValType"
			",b2Fixture_SetRestitution:AS3ValType"

			",b2FixtureDef_new:AS3ValType"
			",b2FixtureDef_SetShape:AS3ValType"
			",b2FixtureDef_GetShape:AS3ValType"

			",b2Draw_new:AS3ValType"
			",b2Draw_SetFlags:AS3ValType"
			",b2Draw_GetFlags:AS3ValType"
			",b2Draw_AppendFlags:AS3ValType"
			",b2Draw_ClearFlags:AS3ValType"

			",b2DestructionListener_new:AS3ValType"

			",b2ContactListener_new:AS3ValType"

			",b2WorldManifold_new:AS3ValType"
			",b2WorldManifold_Initialize:AS3ValType"

			",b2Contact_GetManifold:AS3ValType"
			",b2Contact_GetWorldManifold:AS3ValType"
			",b2Contact_GetFixtureA:AS3ValType"
			",b2Contact_GetFixtureB:AS3ValType"

			",b2ContactFilter_new:AS3ValType"
			",b2ContactFilter_ShouldCollide:AS3ValType"

			",b2BuoyancyControllerDef_new:AS3ValType"
			",b2ConstantAccelControllerDef_new:AS3ValType"
			",b2ConstantForceControllerDef_new:AS3ValType"
			",b2GravityControllerDef_new:AS3ValType"
			",b2TensorDampingControllerDef_new:AS3ValType"
			",b2CustomControllerDef_new:AS3ValType"
			",b2Controller_AddBody:AS3ValType"
			",b2Controller_RemoveBody:AS3ValType"
			",b2Controller_Clear:AS3ValType"
			",b2Controller_GetType:AS3ValType"
			",b2Controller_GetNext:AS3ValType"
			",b2Controller_GetBodyList:AS3ValType"
			",b2CustomController_GetDef:AS3ValType"

			",b2ControllerEdge_GetBody:AS3ValType"
			",b2ControllerEdge_GetController:AS3ValType"

			",b2RayCastInput_new:AS3ValType"
			",b2RayCastOutput_new:AS3ValType"

			",b2QueryCallback_new:AS3ValType"
			",b2RayCastCallback_new:AS3ValType"

			",b2Joint_GetAnchorA:AS3ValType"
			",b2Joint_GetAnchorB:AS3ValType"
			",b2Joint_GetReactionForce:AS3ValType"
			",b2Joint_GetReactionTorque:AS3ValType"
			",b2MouseJointDef_new:AS3ValType"
			",b2MouseJoint_SetTarget:AS3ValType"
			",b2MouseJoint_GetTarget:AS3ValType"
			",b2DistanceJointDef_new:AS3ValType"
			",b2DistanceJointDef_Initialize:AS3ValType"
			",b2FrictionJointDef_new:AS3ValType"

			",b2PrismaticJointDef_new:AS3ValType"
			",b2PrismaticJointDef_Initialize:AS3ValType"
			",b2PrismaticJoint_GetJointTranslation:AS3ValType"
			",b2PrismaticJoint_GetJointSpeed:AS3ValType"
			",b2PrismaticJoint_IsLimitEnabled:AS3ValType"
			",b2PrismaticJoint_EnableLimit:AS3ValType"
			",b2PrismaticJoint_GetLowerLimit:AS3ValType"
			",b2PrismaticJoint_GetUpperLimit:AS3ValType"
			",b2PrismaticJoint_SetLimits:AS3ValType"
			",b2PrismaticJoint_IsMotorEnabled:AS3ValType"
			",b2PrismaticJoint_EnableMotor:AS3ValType"
			",b2PrismaticJoint_SetMotorSpeed:AS3ValType"
			",b2PrismaticJoint_GetMotorSpeed:AS3ValType"
			",b2PrismaticJoint_SetMaxMotorForce:AS3ValType"
			",b2PrismaticJoint_GetMotorForce:AS3ValType"

			",b2RevoluteJointDef_new:AS3ValType"
			",b2RevoluteJointDef_Initialize:AS3ValType"
			",b2RevoluteJoint_GetJointAngle:AS3ValType"
			",b2RevoluteJoint_GetJointSpeed:AS3ValType"
			",b2RevoluteJoint_IsLimitEnabled:AS3ValType"
			",b2RevoluteJoint_EnableLimit:AS3ValType"
			",b2RevoluteJoint_GetLowerLimit:AS3ValType"
			",b2RevoluteJoint_GetUpperLimit:AS3ValType"
			",b2RevoluteJoint_SetLimits:AS3ValType"
			",b2RevoluteJoint_IsMotorEnabled:AS3ValType"
			",b2RevoluteJoint_EnableMotor:AS3ValType"
			",b2RevoluteJoint_SetMotorSpeed:AS3ValType"
			",b2RevoluteJoint_GetMotorSpeed:AS3ValType"
			",b2RevoluteJoint_SetMaxMotorTorque:AS3ValType"
			",b2RevoluteJoint_GetMotorTorque:AS3ValType"

			",b2GearJointDef_new:AS3ValType"
			",b2GearJoint_SetRatio:AS3ValType"
			",b2GearJoint_GetRatio:AS3ValType"

			",b2WeldJointDef_new:AS3ValType"
			",b2WeldJointDef_Initialize:AS3ValType"

			",b2WheelJointDef_new:AS3ValType"
			",b2WheelJointDef_Initialize:AS3ValType"
			",b2WheelJoint_GetJointTranslation:AS3ValType"
			",b2WheelJoint_GetJointSpeed:AS3ValType"
			",b2WheelJoint_IsMotorEnabled:AS3ValType"
			",b2WheelJoint_EnableMotor:AS3ValType"
			",b2WheelJoint_SetMotorSpeed:AS3ValType"
			",b2WheelJoint_GetMotorSpeed:AS3ValType"
			",b2WheelJoint_SetMaxMotorTorque:AS3ValType"
			",b2WheelJoint_GetMaxMotorTorque:AS3ValType"
			",b2WheelJoint_GetMotorTorque:AS3ValType"
			",b2WheelJoint_SetSpringFrequencyHz:AS3ValType"
			",b2WheelJoint_GetSpringFrequencyHz:AS3ValType"
			",b2WheelJoint_SetSpringDampingRatio:AS3ValType"
			",b2WheelJoint_GetSpringDampingRatio:AS3ValType"

			",b2DynamicTree_new:AS3ValType"
			",b2DynamicTree_CreateProxy:AS3ValType"
			",b2DynamicTree_DestroyProxy:AS3ValType"
			",b2DynamicTree_MoveProxy:AS3ValType"
			",b2DynamicTree_GetUserData:AS3ValType"
			",b2DynamicTree_GetFatAABB:AS3ValType"
			",b2DynamicTree_Query:AS3ValType"
			",b2DynamicTree_RayCast:AS3ValType"
			",b2DynamicTree_Validate:AS3ValType"
			",b2DynamicTree_GetHeight:AS3ValType"
			",b2DynamicTree_GetMaxBalance:AS3ValType"
			",b2DynamicTree_GetAreaRatio:AS3ValType"
			",b2DynamicTree_RebuildBottomUp:AS3ValType"

			",b2Manifold_new:AS3ValType"
			",b2Transform_new:AS3ValType"
			",b2Transform_Copy:AS3ValType"
			",b2Transform_SetIdentity:AS3ValType"
			",b2Transform_Set:AS3ValType"
			",b2Transform_GetAngle:AS3ValType"
			",b2Sweep_new:AS3ValType"
			",b2Sweep_GetTransform:AS3ValType"
			",b2Sweep_Advance:AS3ValType"
			",b2Sweep_Normalize:AS3ValType"
			",b2Sweep_Copy:AS3ValType"

			",b2DistanceInput_new:AS3ValType"
			",b2DistanceOutput_new:AS3ValType"
			",b2SimplexCache_new:AS3ValType"
			",b2TOIInput_new:AS3ValType"
			",b2TOIOutput_new:AS3ValType"
			",b2TimeOfImpact_TimeOfImpact:AS3ValType"
			",b2DistanceProxy_Set:AS3ValType"
			",b2DistanceProxy_GetSupport:AS3ValType"
			",b2DistanceProxy_GetSupportVertex:AS3ValType"
			",b2DistanceProxy_GetVertexCount:AS3ValType"
			",b2DistanceProxy_GetVertex:AS3ValType"
			",b2Distance_Distance:AS3ValType"
			",b2Math_MulX:AS3ValType"
			",b2Math_MulXT:AS3ValType"
			",b2Math_MulA:AS3ValType"
			",b2Math_MulAT:AS3ValType"
			",b2Math_Clamp:AS3ValType"
			",b2Math_CrossVV:AS3ValType"
			",b2Math_CrossVF:AS3ValType"
			",b2Math_CrossFV:AS3ValType"
			",b2Math_CrossV3:AS3ValType"

			",b2Collision_CollideCircles:AS3ValType"
			",b2Collision_CollidePolygonAndCircle:AS3ValType"
			",b2Collision_CollidePolygons:AS3ValType"
			",b2Collision_CollideEdgeAndCircle:AS3ValType"
			",b2Collision_CollideEdgeAndPolygon:AS3ValType"
			",b2Collision_TestOverlap:AS3ValType"

			",b2_gjkCalls_get:AS3ValType"
			",b2_gjkCalls_set:AS3ValType"
			",b2_gjkIters_get:AS3ValType"
			",b2_gjkIters_set:AS3ValType"
			",b2_gjkMaxIters_get:AS3ValType"
			",b2_gjkMaxIters_set:AS3ValType"
			",b2_toiCalls_get:AS3ValType"
			",b2_toiCalls_set:AS3ValType"
			",b2_toiIters_get:AS3ValType"
			",b2_toiIters_set:AS3ValType"
			",b2_toiMaxIters_get:AS3ValType"
			",b2_toiMaxIters_set:AS3ValType"
			",b2_toiRootIters_get:AS3ValType"
			",b2_toiRootIters_set:AS3ValType"
			",b2_toiMaxRootIters_get:AS3ValType"
			",b2_toiMaxRootIters_set:AS3ValType"
			",b2_version_get:AS3ValType"

			,AS3_Function(NULL,b2AABB_new)
			,AS3_Function(NULL,b2AABB_Copy)
			,AS3_Function(NULL,b2AABB_GetCenter)
			,AS3_Function(NULL,b2AABB_GetExtents)
			,AS3_Function(NULL,b2AABB_Combine)
			,AS3_Function(NULL,b2AABB_Contains)
			,AS3_Function(NULL,b2AABB_RayCast)


			,AS3_Function(NULL,b2Color_new)
			,AS3_Function(NULL,b2Color_Set)

			,AS3_Function(NULL,b2Vec2_new)
			,AS3_Function(NULL,b2Vec2_Array_new)
			,AS3_Function(NULL,b2Vec2_SetZero)
			,AS3_Function(NULL,b2Vec2_Set)
			,AS3_Function(NULL,b2Vec2_Length)
			,AS3_Function(NULL,b2Vec2_LengthSquared)
			,AS3_Function(NULL,b2Vec2_Normalize)
			,AS3_Function(NULL,b2Vec2_IsValid)

			,AS3_Function(NULL,b2Vec3_new)

			,AS3_Function(NULL,b2World_new)
			,AS3_Function(NULL,b2World_delete)
			,AS3_Function(NULL,b2World_SetDestructionListener)
			,AS3_Function(NULL,b2World_SetContactFilter)
			,AS3_Function(NULL,b2World_GetContactFilter)
			,AS3_Function(NULL,b2World_SetContactListener)
			,AS3_Function(NULL,b2World_SetDebugDraw)
			,AS3_Function(NULL,b2World_CreateBody)
			,AS3_Function(NULL,b2World_DestroyBody)
			,AS3_Function(NULL,b2World_CreateJoint)
			,AS3_Function(NULL,b2World_DestroyJoint)
			,AS3_Function(NULL,b2World_CreateController)
			,AS3_Function(NULL,b2World_DestroyController)
			,AS3_Function(NULL,b2World_GetControllerList)
			,AS3_Function(NULL,b2World_Step)
			,AS3_Function(NULL,b2World_ClearForces)
			,AS3_Function(NULL,b2World_DrawDebugData)
			,AS3_Function(NULL,b2World_QueryAABB)
			,AS3_Function(NULL,b2World_RayCast)
			,AS3_Function(NULL,b2World_GetBodyList)
			,AS3_Function(NULL,b2World_SetGravity)
			,AS3_Function(NULL,b2World_GetGravity)

			,AS3_Function(NULL,b2BodyDef_new)
			,AS3_Function(NULL,b2BodyDef_SetType)
			,AS3_Function(NULL,b2BodyDef_GetType)

			,AS3_Function(NULL,b2Body_CreateFixture)
			,AS3_Function(NULL,b2Body_CreateFixtureByShape)
			,AS3_Function(NULL,b2Body_DestroyFixture)
			,AS3_Function(NULL,b2Body_SetTransform)
			,AS3_Function(NULL,b2Body_GetTransform)
			,AS3_Function(NULL,b2Body_GetPosition)
			,AS3_Function(NULL,b2Body_GetAngle)
			,AS3_Function(NULL,b2Body_GetWorldCenter)
			,AS3_Function(NULL,b2Body_GetLocalCenter)
			,AS3_Function(NULL,b2Body_SetLinearVelocity)
			,AS3_Function(NULL,b2Body_GetLinearVelocity)
			,AS3_Function(NULL,b2Body_SetAngularVelocity)
			,AS3_Function(NULL,b2Body_GetAngularVelocity)
			,AS3_Function(NULL,b2Body_ApplyForce)
			,AS3_Function(NULL,b2Body_ApplyTorque)
			,AS3_Function(NULL,b2Body_ApplyLinearImpulse)
			,AS3_Function(NULL,b2Body_ApplyAngularImpulse)
			,AS3_Function(NULL,b2Body_GetMass)
			,AS3_Function(NULL,b2Body_GetInertia)
			,AS3_Function(NULL,b2Body_GetMassData)
			,AS3_Function(NULL,b2Body_SetMassData)
			,AS3_Function(NULL,b2Body_ResetMassData)
			,AS3_Function(NULL,b2Body_GetWorldPoint)
			,AS3_Function(NULL,b2Body_GetWorldCenter)
			,AS3_Function(NULL,b2Body_GetLocalPoint)
			,AS3_Function(NULL,b2Body_GetLocalVector)
			,AS3_Function(NULL,b2Body_GetLinearVelocityFromWorldPoint)
			,AS3_Function(NULL,b2Body_GetLinearVelocityFromLocalPoint)
			,AS3_Function(NULL,b2Body_GetLinearDamping)
			,AS3_Function(NULL,b2Body_SetLinearDamping)
			,AS3_Function(NULL,b2Body_GetAngularDamping)
			,AS3_Function(NULL,b2Body_SetAngularDamping)
			,AS3_Function(NULL,b2Body_SetGravityScale)
			,AS3_Function(NULL,b2Body_GetGravityScale)
			,AS3_Function(NULL,b2Body_SetType)
			,AS3_Function(NULL,b2Body_GetType)
			,AS3_Function(NULL,b2Body_SetBullet)
			,AS3_Function(NULL,b2Body_IsBullet)
			,AS3_Function(NULL,b2Body_SetSleepingAllowed)
			,AS3_Function(NULL,b2Body_IsSleepingAllowed)
			,AS3_Function(NULL,b2Body_SetAwake)
			,AS3_Function(NULL,b2Body_IsAwake)
			,AS3_Function(NULL,b2Body_SetActive)
			,AS3_Function(NULL,b2Body_IsActive)
			,AS3_Function(NULL,b2Body_SetFixedRotation)
			,AS3_Function(NULL,b2Body_IsFixedRotation)
			,AS3_Function(NULL,b2Body_GetFixtureList)
//			,AS3_Function(NULL,b2Body_GetJointList)
//			,AS3_Function(NULL,b2Body_GetContactList)
			,AS3_Function(NULL,b2Body_GetNext)
//			,AS3_Function(NULL,b2Body_GetUserData)
//			,AS3_Function(NULL,b2Body_SetUserData)
//			,AS3_Function(NULL,b2Body_GetWorld)

			,AS3_Function(NULL,b2MassData_new)

			,AS3_Function(NULL,b2Mat22_new)
			,AS3_Function(NULL,b2Mat22_Set)

			,AS3_Function(NULL,b2Shape_TestPoint)

			,AS3_Function(NULL,b2EdgeShape_new)
			,AS3_Function(NULL,b2EdgeShape_Set)

			,AS3_Function(NULL,b2CircleShape_new)

			,AS3_Function(NULL,b2PolygonShape_new)
			,AS3_Function(NULL,b2PolygonShape_Set)
			,AS3_Function(NULL,b2PolygonShape_SetAsBox)
			,AS3_Function(NULL,b2PolygonShape_SetAsBoxByCenter)
			,AS3_Function(NULL,b2PolygonShape_GetVertexCount)

			,AS3_Function(NULL,b2LoopShape_new)
			,AS3_Function(NULL,b2LoopShape_Set)

			,AS3_Function(NULL,b2Fixture_GetType)
			,AS3_Function(NULL,b2Fixture_GetShape)
			,AS3_Function(NULL,b2Fixture_SetSensor)
			,AS3_Function(NULL,b2Fixture_IsSensor)			
			,AS3_Function(NULL,b2Fixture_SetFilterData)
			,AS3_Function(NULL,b2Fixture_GetFilterData)
			,AS3_Function(NULL,b2Fixture_GetBody)
			,AS3_Function(NULL,b2Fixture_GetNext)
			,AS3_Function(NULL,b2Fixture_TestPoint)
			,AS3_Function(NULL,b2Fixture_GetMassData)
			,AS3_Function(NULL,b2Fixture_SetDensity)
			,AS3_Function(NULL,b2Fixture_GetDensity)
			,AS3_Function(NULL,b2Fixture_GetFriction)
			,AS3_Function(NULL,b2Fixture_SetFriction)
			,AS3_Function(NULL,b2Fixture_GetRestitution)
			,AS3_Function(NULL,b2Fixture_SetRestitution)

			,AS3_Function(NULL,b2FixtureDef_new)
			,AS3_Function(NULL,b2FixtureDef_SetShape)
			,AS3_Function(NULL,b2FixtureDef_GetShape)

			,AS3_Function(NULL,b2Draw_new)
			,AS3_Function(NULL,b2Draw_SetFlags)
			,AS3_Function(NULL,b2Draw_GetFlags)
			,AS3_Function(NULL,b2Draw_AppendFlags)
			,AS3_Function(NULL,b2Draw_ClearFlags)

			,AS3_Function(NULL,b2DestructionListener_new)

			,AS3_Function(NULL,b2ContactListener_new)

			,AS3_Function(NULL,b2WorldManifold_new)
			,AS3_Function(NULL,b2WorldManifold_Initialize)

			,AS3_Function(NULL,b2Contact_GetManifold)
			,AS3_Function(NULL,b2Contact_GetWorldManifold)
			,AS3_Function(NULL,b2Contact_GetFixtureA)
			,AS3_Function(NULL,b2Contact_GetFixtureB)

			,AS3_Function(NULL,b2ContactFilter_new)
			,AS3_Function(NULL,b2ContactFilter_ShouldCollide)

			,AS3_Function(NULL,b2BuoyancyControllerDef_new)
			,AS3_Function(NULL,b2ConstantAccelControllerDef_new)
			,AS3_Function(NULL,b2ConstantForceControllerDef_new)
			,AS3_Function(NULL,b2GravityControllerDef_new)
			,AS3_Function(NULL,b2TensorDampingControllerDef_new)
			,AS3_Function(NULL,b2CustomControllerDef_new)
			,AS3_Function(NULL,b2Controller_AddBody)
			,AS3_Function(NULL,b2Controller_RemoveBody)
			,AS3_Function(NULL,b2Controller_Clear)
			,AS3_Function(NULL,b2Controller_GetType)
			,AS3_Function(NULL,b2Controller_GetNext)
			,AS3_Function(NULL,b2Controller_GetBodyList)
			,AS3_Function(NULL,b2CustomController_GetDef)

			,AS3_Function(NULL,b2ControllerEdge_GetBody)
			,AS3_Function(NULL,b2ControllerEdge_GetController)

			,AS3_Function(NULL,b2RayCastInput_new)
			,AS3_Function(NULL,b2RayCastOutput_new)

			,AS3_Function(NULL,b2QueryCallback_new)
			,AS3_Function(NULL,b2RayCastCallback_new)

			,AS3_Function(NULL,b2Joint_GetAnchorA)
			,AS3_Function(NULL,b2Joint_GetAnchorB)
			,AS3_Function(NULL,b2Joint_GetReactionForce)
			,AS3_Function(NULL,b2Joint_GetReactionTorque)
			,AS3_Function(NULL,b2MouseJointDef_new)
			,AS3_Function(NULL,b2MouseJoint_SetTarget)
			,AS3_Function(NULL,b2MouseJoint_GetTarget)
			,AS3_Function(NULL,b2DistanceJointDef_new)
			,AS3_Function(NULL,b2DistanceJointDef_Initialize)
			,AS3_Function(NULL,b2FrictionJointDef_new)

			,AS3_Function(NULL,b2PrismaticJointDef_new)
			,AS3_Function(NULL,b2PrismaticJointDef_Initialize)
			,AS3_Function(NULL,b2PrismaticJoint_GetJointTranslation)
			,AS3_Function(NULL,b2PrismaticJoint_GetJointSpeed)
			,AS3_Function(NULL,b2PrismaticJoint_IsLimitEnabled)
			,AS3_Function(NULL,b2PrismaticJoint_EnableLimit)
			,AS3_Function(NULL,b2PrismaticJoint_GetLowerLimit)
			,AS3_Function(NULL,b2PrismaticJoint_GetUpperLimit)
			,AS3_Function(NULL,b2PrismaticJoint_SetLimits)
			,AS3_Function(NULL,b2PrismaticJoint_IsMotorEnabled)
			,AS3_Function(NULL,b2PrismaticJoint_EnableMotor)
			,AS3_Function(NULL,b2PrismaticJoint_SetMotorSpeed)
			,AS3_Function(NULL,b2PrismaticJoint_GetMotorSpeed)
			,AS3_Function(NULL,b2PrismaticJoint_SetMaxMotorForce)
			,AS3_Function(NULL,b2PrismaticJoint_GetMotorForce)

			,AS3_Function(NULL,b2RevoluteJointDef_new)
			,AS3_Function(NULL,b2RevoluteJointDef_Initialize)
			,AS3_Function(NULL,b2RevoluteJoint_GetJointAngle)
			,AS3_Function(NULL,b2RevoluteJoint_GetJointSpeed)
			,AS3_Function(NULL,b2RevoluteJoint_IsLimitEnabled)
			,AS3_Function(NULL,b2RevoluteJoint_EnableLimit)
			,AS3_Function(NULL,b2RevoluteJoint_GetLowerLimit)
			,AS3_Function(NULL,b2RevoluteJoint_GetUpperLimit)
			,AS3_Function(NULL,b2RevoluteJoint_SetLimits)
			,AS3_Function(NULL,b2RevoluteJoint_IsMotorEnabled)
			,AS3_Function(NULL,b2RevoluteJoint_EnableMotor)
			,AS3_Function(NULL,b2RevoluteJoint_SetMotorSpeed)
			,AS3_Function(NULL,b2RevoluteJoint_GetMotorSpeed)
			,AS3_Function(NULL,b2RevoluteJoint_SetMaxMotorTorque)
			,AS3_Function(NULL,b2RevoluteJoint_GetMotorTorque)

			,AS3_Function(NULL,b2GearJointDef_new)
			,AS3_Function(NULL,b2GearJoint_SetRatio)
			,AS3_Function(NULL,b2GearJoint_GetRatio)

			,AS3_Function(NULL,b2WeldJointDef_new)
			,AS3_Function(NULL,b2WeldJointDef_Initialize)

			,AS3_Function(NULL,b2WheelJointDef_new)
			,AS3_Function(NULL,b2WheelJointDef_Initialize)
			,AS3_Function(NULL,b2WheelJoint_GetJointTranslation)
			,AS3_Function(NULL,b2WheelJoint_GetJointSpeed)
			,AS3_Function(NULL,b2WheelJoint_IsMotorEnabled)
			,AS3_Function(NULL,b2WheelJoint_EnableMotor)
			,AS3_Function(NULL,b2WheelJoint_SetMotorSpeed)
			,AS3_Function(NULL,b2WheelJoint_GetMotorSpeed)
			,AS3_Function(NULL,b2WheelJoint_SetMaxMotorTorque)
			,AS3_Function(NULL,b2WheelJoint_GetMaxMotorTorque)
			,AS3_Function(NULL,b2WheelJoint_GetMotorTorque)
			,AS3_Function(NULL,b2WheelJoint_SetSpringFrequencyHz)
			,AS3_Function(NULL,b2WheelJoint_GetSpringFrequencyHz)
			,AS3_Function(NULL,b2WheelJoint_SetSpringDampingRatio)
			,AS3_Function(NULL,b2WheelJoint_GetSpringDampingRatio)

			,AS3_Function(NULL,b2DynamicTree_new)
			,AS3_Function(NULL,b2DynamicTree_CreateProxy)
			,AS3_Function(NULL,b2DynamicTree_DestroyProxy)
			,AS3_Function(NULL,b2DynamicTree_MoveProxy)
			,AS3_Function(NULL,b2DynamicTree_GetUserData)
			,AS3_Function(NULL,b2DynamicTree_GetFatAABB)
			,AS3_Function(NULL,b2DynamicTree_Query)
			,AS3_Function(NULL,b2DynamicTree_RayCast)
			,AS3_Function(NULL,b2DynamicTree_Validate)
			,AS3_Function(NULL,b2DynamicTree_GetHeight)
			,AS3_Function(NULL,b2DynamicTree_GetMaxBalance)
			,AS3_Function(NULL,b2DynamicTree_GetAreaRatio)
			,AS3_Function(NULL,b2DynamicTree_RebuildBottomUp)

			,AS3_Function(NULL,b2Manifold_new)
			,AS3_Function(NULL,b2Transform_new)
			,AS3_Function(NULL,b2Transform_Copy)
			,AS3_Function(NULL,b2Transform_SetIdentity)
			,AS3_Function(NULL,b2Transform_Set)
			,AS3_Function(NULL,b2Transform_GetAngle)
			,AS3_Function(NULL,b2Sweep_new)
			,AS3_Function(NULL,b2Sweep_GetTransform)
			,AS3_Function(NULL,b2Sweep_Advance)
			,AS3_Function(NULL,b2Sweep_Normalize)
			,AS3_Function(NULL,b2Sweep_Copy)
			,AS3_Function(NULL,b2DistanceInput_new)
			,AS3_Function(NULL,b2DistanceOutput_new)
			,AS3_Function(NULL,b2SimplexCache_new)
			,AS3_Function(NULL,b2TOIInput_new)
			,AS3_Function(NULL,b2TOIOutput_new)
			,AS3_Function(NULL,b2TimeOfImpact_TimeOfImpact)
			,AS3_Function(NULL,b2DistanceProxy_Set)
			,AS3_Function(NULL,b2DistanceProxy_GetSupport)
			,AS3_Function(NULL,b2DistanceProxy_GetSupportVertex)
			,AS3_Function(NULL,b2DistanceProxy_GetVertexCount)
			,AS3_Function(NULL,b2DistanceProxy_GetVertex)
			,AS3_Function(NULL,b2Distance_Distance)
			,AS3_Function(NULL,b2Math_MulX)
			,AS3_Function(NULL,b2Math_MulXT)
			,AS3_Function(NULL,b2Math_MulA)
			,AS3_Function(NULL,b2Math_MulAT)
			,AS3_Function(NULL,b2Math_Clamp)
			,AS3_Function(NULL,b2Math_CrossVV)
			,AS3_Function(NULL,b2Math_CrossVF)
			,AS3_Function(NULL,b2Math_CrossFV)
			,AS3_Function(NULL,b2Math_CrossV3)

			,AS3_Function(NULL,b2Collision_CollideCircles)
			,AS3_Function(NULL,b2Collision_CollidePolygonAndCircle)
			,AS3_Function(NULL,b2Collision_CollidePolygons)
			,AS3_Function(NULL,b2Collision_CollideEdgeAndCircle)
			,AS3_Function(NULL,b2Collision_CollideEdgeAndPolygon)
			,AS3_Function(NULL,b2Collision_TestOverlap)

			,AS3_Function(NULL,b2_gjkCalls_get)
			,AS3_Function(NULL,b2_gjkCalls_set)
			,AS3_Function(NULL,b2_gjkIters_get)
			,AS3_Function(NULL,b2_gjkIters_set)
			,AS3_Function(NULL,b2_gjkMaxIters_get)
			,AS3_Function(NULL,b2_gjkMaxIters_set)
			,AS3_Function(NULL,b2_toiCalls_get)
			,AS3_Function(NULL,b2_toiCalls_set)
			,AS3_Function(NULL,b2_toiIters_get)
			,AS3_Function(NULL,b2_toiIters_set)
			,AS3_Function(NULL,b2_toiMaxIters_get)
			,AS3_Function(NULL,b2_toiMaxIters_set)
			,AS3_Function(NULL,b2_toiRootIters_get)
			,AS3_Function(NULL,b2_toiRootIters_set)
			,AS3_Function(NULL,b2_toiMaxRootIters_get)
			,AS3_Function(NULL,b2_toiMaxRootIters_set)
			,AS3_Function(NULL,b2_version_get)

	);
}